Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

253
Vistas
Been facing an issue when trying to run the html file on Chrome. It keeps showing me the error "Cannot set properties of null (setting 'textcontent')"

I've tried changing the .textcontent to .innertext and then i get the error message "Cannot set properties of null (setting 'innertext')". Could it be that it's the HTML that is faulty or what because they are all showing the same error when run on chrome. What can I do please? ta

let cards = [];
let firstcard = randomNumber();
let secondcard = randomNumber();
let sum = firstcard + secondcard;
let blackjackvalue = false; // checks for blackjack value
let isalive = true; //to check if the user can play only when the game is true
let message = "";
let gamestate = document.getElementById(message); // get the gamestate
let sumEl = document.getElementById(sum); //holding the sum
let cardEl = document.getElementById("card"); //holding the card
let playerEl = document.getElementById("player"); //holding the player details
let playerdetails = {
  name: "John",
  wins: 5,
  amount: "$" + 500,
};
playerEl.innertext = playerdetails.name + playerdetails.wins + playerdetails.amount;

function randomNumber() {
  let jacknumbers = Math.floor(Math.random() * 14) + 1; //produces random numbers between 1 and 13 to be used by first and second card
  return jacknumbers;
  if (jacknumbers == 1) {
    return 11;
  } //these if conditions are for setting the ace card to either 1 or 11...not really sure
  else if (jacknumbers > 10) {
    return 10;
  } else {
    return jacknumbers;
  }
}


function start() {
  // let firstcard = randomNumber();
  // let secondcard = randomNumber();
  let cards = [firstcard, secondcard];
  let sum = [firstcard + secondcard];
  rendergamestate();
} //when this is called, it triggers the rendergamestate function
function rendergamestate() {
  card.innertext = "cards:" + " " + firstcard + " " + secondcard;
  for (i = 0; i < card.length; i += 1) {
    card.innertext += cards[i] + " ";
    //using the for loop to display the card contents
  }
  sumEl.innertext = "sum:" + " " + sum;
  if (sum <= 20) {
    message = "Do you want to draw a new card?";
    blackjackvalue = false;
  } else if (sum === 21) {
    message = "Blackjack!";
    blackjackvalue = true;
  } else {
    message = "You are out";
    isalive = false;
    blackjackvalue = false;
  }
  gamestate.innertext = message;
}
function newcard() {
  //this button is for the user to add a new card to the already existing cards
  if (isalive === true && blackjackvalue === false) {
    let thirdcard = randomNumber();
    sum += thirdcard; // sum=sum+thirdcard;
    cards.push(thirdcard);
    rendergamestate(); //calling the function to start the game
  }
}

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda